package day13;
//测试克隆
//1.实现一个接口Cloneable(表示允许克隆)
//否则出现CloneNotSupportedException
//2.重写clone()
//3.如果
public class demo {
    public static void main(String[] args) throws CloneNotSupportedException {
        A a = new A();
        a.id=100;
        a.name="万冲";
        a.b = new B();
        A a2 = (A)a.clone();
        //浅克隆成功  两个引用地址
        System.out.println(a);
        System.out.println(a2);
        a.id=1000;
        a.name="武安";
        a.print();
        a2.print();
    }
}

class A implements Cloneable{
    Integer id;//基本类型
    String name;//String
    B b;//引用类型
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public void print(){
        System.out.println("id:"+id+",name:"+name+",b:"+b);
    }
}

class B{

}
